let storage = bui.storage();
let org;
loader.define(function (require, exports, module, global) {
    let pageview = {
        init() {
            let uiLoading = bui.loading({
                appendTo:"#fbZjLoading",
                width: 40,
                height: 40,
                opacity: 0.5,
                text:"加载中。。。",
                autoClose: false
            });
            uiLoading.show()

            let params = module.props;

            router.$("#fbZjFh").click(function () {
                switch (params.tzSign) {
                    case "0":
                        storage.set("tzPage", 0)
                        router.replace({url: "pages/mainIndex/mainIndex.html"});
                        break
                    default:
                        let article = storage.get("tzArticleInfo",0)
                        router.replace({ url: "pages/articleInfo/articleInfo.html", param: {id: article.id, glUserid: article.glUserid}});
                        break
                }
            })

            org = storage.get("org",0)
            if (org != null) {
                router.$("#nameFbZj").html("发布" +org.description + "信息")
                router.$("#csFb").html(org.description)
            }

            //自定义弹出菜单初始化
            let dialog = bui.dialog({
                id: "#actionsheet",
                position:"bottom",
                effect:"fadeInUp",
                onMask: function (argument) {
                    dialog.close();
                }
            });

            //查询菜单
            bui.ajax({
                url: global.api.getCountryList,
                data: {type: '1', parent: '1'},
                method: "POST"
            }).then(function(res){
                let data = res.data
                if (data) {
                    let html = ""
                    data.forEach((da, index) => {
                        if (index % 4 == 0) {
                            if (index > 0) {
                                html += '</div>'
                            }
                            html += '<div class="bui-box">'
                        }

                        html += '<div class="span1 menuListChildren" id="'+da.id+'" name="'+da.name+'">\n' +
                            '                                <div class="icons-round">\n' +
                            '                                    <img src="'+da.imgUrl+'" style="width: 100%; height: 100%">\n' +
                            '                                </div>\n' +
                            '                                <div class="span1">'+da.name+'</div>\n' +
                            '                            </div>'
                    })
                    if (data.length % 4 != 0) {
                        for (let i = 0; i < 4 - data.length % 4; i++) {
                            html += '<div class="span1"></div>'
                        }
                    }
                    html += '     </div>'
                    router.$("#fbTypeContent").html(html)

                    router.$(".menuListChildren").click(function () {
                        uiLoading.show()
                        let id = $(this).attr("id") //一级分类id
                        let name = $(this).attr("name") //一级分类id
                        router.$("#cateChildrenTitle").html("发布“" + name + "”信息")
                        //查询下拉菜单
                        bui.ajax({
                            url: global.api.getTypeList,
                            data: {type: '1', parent: id},
                            method: "POST"
                        }).then(function(res){
                            let data = res.data
                            let html = ''
                            data.forEach((da, index) => {
                                if (index % 7 == 0) {
                                    if (index > 0) {
                                        html += '</ul></div>'
                                    }
                                    html += '<div class="span1" style="margin-right: 1px">'+
                                        '<ul class="bui-list">'
                                }
                                html += '<li class="bui-btn cateChildren" id="'+da.id+'" name="'+da.name+'" validSign="'+da.validSign+'">\n' +
                                    '                    <i class="icon"><img src="images/icon-weibo.png" alt=""></i>'+ da.name +
                                    '                </li>'
                            })
                            if (data.length > 0) {
                                if (data.length % 7 != 0) {
                                    html += '<li></li>'
                                }
                                html += '</div>'
                            }
                            router.$("#cateChilderContent").html(html)
                            dialog.open();

                            router.$('.cateChildren').click(function () {
                                let cId = $(this).attr("id")
                                let cName = $(this).attr("name")
                                let validSign = $(this).attr("validSign")
                                storage.set('cateDo', {id: cId, parent: id})
                                router.replace({ url: "pages/fb/fb.html"});
                            })

                            uiLoading.stop()
                        })
                    })
                }
                uiLoading.stop()
            })
        }
    };

    // 初始化
    pageview.init();

    // 输出模块
    return pageview;
})
